package br.com.cardoso.videostore.model.entity;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.cardoso.persistence.EntityBean;

@Entity
@Table(name = "film")
public class FilmEntity extends EntityBean {

	private static final long serialVersionUID = 1L;
	
	private String title;
	private String sinopse;
	private String duration;
	
	private ClassificationEntity classification;
	private CategoryEntity category;
	private LanguageEntity language;
	
	@ManyToMany(fetch=FetchType.LAZY) 
	@JoinTable(name="film_actor",
	 joinColumns=@JoinColumn(name="actor_id"), 
	 inverseJoinColumns=@JoinColumn(name="film_id"))
	private List<PersonEntity> actors;
	
	@ManyToMany(fetch=FetchType.LAZY) 
	@JoinTable(name="film_director",
	 joinColumns=@JoinColumn(name="director_id"), 
	 inverseJoinColumns=@JoinColumn(name="film_id"))
	private List<PersonEntity> directors;

	@Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
	public Long getId() {
		return super.id;
	}

	@Column(name = "title")
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Column(name = "sinopse")
	public String getSinopse() {
		return sinopse;
	}

	public void setSinopse(String sinopse) {
		this.sinopse = sinopse;
	}

	@Column(name = "duration")
	public String getDuration() {
		return duration;
	}

	public void setDuration(String duration) {
		this.duration = duration;
	}

	@ManyToOne
	@JoinColumn(name = "language_id", referencedColumnName = "id")
	public LanguageEntity getLanguage() {
		return language;
	}

	public void setLanguage(LanguageEntity language) {
		this.language = language;
	}

	@ManyToOne
	@JoinColumn(name = "category_id", referencedColumnName = "id")
	public CategoryEntity getCategory() {
		return category;
	}

	public void setCategory(CategoryEntity category) {
		this.category = category;
	}

	@ManyToOne
	@JoinColumn(name = "classification_id", referencedColumnName = "id")
	public ClassificationEntity getClassification() {
		return classification;
	}

	public void setClassification(ClassificationEntity classification) {
		this.classification = classification;
	}

	@ManyToMany(fetch=FetchType.LAZY) 
	@JoinTable(name="film_actor",
	 				joinColumns=@JoinColumn(name="actor_id"), 
	 				inverseJoinColumns=@JoinColumn(name="film_id"))
	public List<PersonEntity> getActors() {
		return actors;
	}

	public void setActors(List<PersonEntity> actors) {
		this.actors = actors;
	}

	@ManyToMany(fetch=FetchType.LAZY) 
	@JoinTable(name="film_director",
	 joinColumns=@JoinColumn(name="director_id"), 
	 inverseJoinColumns=@JoinColumn(name="film_id"))
	public List<PersonEntity> getDirectors() {
		return directors;
	}

	public void setDirectors(List<PersonEntity> directors) {
		this.directors = directors;
	}

}